home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / prefix.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  69KB  |  1,674 lines

  1. /***********************************************************************/
  2. /* PREFIX.C - Prefix commands.                                         */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1995 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Id: prefix.c 2.0 1995/01/26 16:31:36 MH Release MH $
  41. */
  42.  
  43. #include <stdio.h>
  44.  
  45. #include "the.h"
  46. #include "proto.h"
  47. /*-------------------------- declarations -----------------------------*/
  48. #ifdef PROTO
  49. static short parse_prefix_command(PPC *,CHARTYPE *,CHARTYPE *);
  50. static short invalidate_prefix(PPC *);
  51. static short prefix_makecurr(PPC *,short,LINETYPE);
  52. static short prefix_add(PPC *,short,LINETYPE);
  53. static short prefix_duplicate(PPC *,short,LINETYPE);
  54. static short prefix_copy(PPC *,short,LINETYPE);
  55. static short prefix_move(PPC *,short,LINETYPE);
  56. static short prefix_delete(PPC *,short,LINETYPE);
  57. static short prefix_shift_left(PPC *,short,LINETYPE);
  58. static short prefix_shift_right(PPC *,short,LINETYPE);
  59. static short prefix_tabline(PPC *,short,LINETYPE);
  60. static short prefix_scale(PPC *,short,LINETYPE);
  61. static short prefix_show(PPC *,short,LINETYPE);
  62. static short prefix_exclude(PPC *,short,LINETYPE);
  63. static short prefix_block_duplicate(PPC *,short,LINETYPE);
  64. static short prefix_block_copy(PPC *,short,LINETYPE);
  65. static short prefix_block_move(PPC *,short,LINETYPE);
  66. static short prefix_block_delete(PPC *,short,LINETYPE);
  67. static short prefix_block_shift_left(PPC *,short,LINETYPE);
  68. static short prefix_block_shift_right(PPC *,short,LINETYPE);
  69. static short prefix_block_exclude(PPC *,short,LINETYPE);
  70. static PPC *find_bottom_ppc(PPC *,short);
  71. static PPC *find_target_ppc(void);
  72. static PPC *calculate_target_line(void);
  73. static short try_rexx_prefix_macro(PPC *);
  74. static CHARTYPE *substr(CHARTYPE *, CHARTYPE *, short, short);
  75. #else
  76. static short parse_prefix_command();
  77. static short invalidate_prefix();
  78. static short prefix_makecurr();
  79. static short prefix_add();
  80. static short prefix_duplicate();
  81. static short prefix_copy();
  82. static short prefix_move();
  83. static short prefix_delete();
  84. static short prefix_shift_left();
  85. static short prefix_shift_right();
  86. static short prefix_tabline();
  87. static short prefix_scale();
  88. static short prefix_show();
  89. static short prefix_exclude();
  90. static short prefix_block_duplicate();
  91. static short prefix_block_copy();
  92. static short prefix_block_move();
  93. static short prefix_block_delete();
  94. static short prefix_block_shift_left();
  95. static short prefix_block_shift_right();
  96. static short prefix_block_exclude();
  97. static PPC *find_bottom_ppc();
  98. static PPC *find_target_ppc();
  99. static PPC *calculate_target_line();
  100. static short try_rexx_prefix_macro();
  101. static CHARTYPE *substr();
  102. #endif
  103. /*---------------------------------------------------------------------*/
  104. /* The following two are to specify the first and last items in the    */
  105. /* linked list for prefix synonyms.                                    */
  106. /*---------------------------------------------------------------------*/
  107. LINE *first_prefix_synonym=NULL;
  108. LINE *last_prefix_synonym=NULL;
  109. /*---------------------------------------------------------------------*/
  110.  
  111. #define PPC_NO_TARGET        (-1)
  112. #define PPC_NO_COMMAND       (-2)
  113. #define PPC_TARGET_PREVIOUS  0
  114. #define PPC_TARGET_FOLLOWING 1
  115. /* the above two defines correspond to the position in the pc[] array  */
  116. /* and should be changed if the position in pc[] array changes.        */
  117.  
  118. #define NUMBER_PREFIX_COMMANDS 22
  119.  static PREFIX_COMMAND pc[NUMBER_PREFIX_COMMANDS] =
  120.   {
  121.    {(CHARTYPE *)"p",1,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,NULL,1L,FALSE,FALSE},
  122.    {(CHARTYPE *)"f",1,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,NULL,1L,FALSE,FALSE},
  123.    {(CHARTYPE *)"tabl",4,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,prefix_tabline,1L,FALSE,FALSE},
  124.    {(CHARTYPE *)"scale",5,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,prefix_scale,1L,FALSE,FALSE},
  125.    {(CHARTYPE *)"\"\"",2,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_block_duplicate,1L,FALSE,FALSE},
  126.    {(CHARTYPE *)"cc",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,prefix_block_copy,1L,FALSE,FALSE},
  127.    {(CHARTYPE *)"mm",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE,prefix_block_move,1L,FALSE,FALSE},
  128.    {(CHARTYPE *)"dd",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_delete,1L,FALSE,FALSE},
  129.    {(CHARTYPE *)"xx",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_exclude,1L,FALSE,FALSE},
  130.    {(CHARTYPE *)"<<",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_shift_left,1L,FALSE,FALSE},
  131.    {(CHARTYPE *)">>",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_block_shift_right,1L,FALSE,FALSE},
  132.    {(CHARTYPE *)"\"",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_duplicate,1L,FALSE,FALSE},
  133.    {(CHARTYPE *)"c",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_copy,1L,FALSE,FALSE},
  134.    {(CHARTYPE *)"m",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_move,1L,FALSE,FALSE},
  135.    {(CHARTYPE *)"d",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_delete,1L,FALSE,FALSE},
  136.    {(CHARTYPE *)"s",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_show,MAX_LONG,TRUE,TRUE},
  137.    {(CHARTYPE *)"x",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_exclude,1L,FALSE,FALSE},
  138.    {(CHARTYPE *)"<",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_left,1L,FALSE,FALSE},
  139.    {(CHARTYPE *)">",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_right,1L,FALSE,FALSE},
  140.    {(CHARTYPE *)"i",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,prefix_add,1L,FALSE,FALSE},
  141.    {(CHARTYPE *)"a",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,prefix_add,1L,FALSE,FALSE},
  142.    {(CHARTYPE *)"/",1,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,prefix_makecurr,1L,FALSE,FALSE},
  143.   };
  144.  
  145. LINETYPE prefix_current_line;
  146. bool in_prefix_macro=FALSE;     /* indicate if processing prefix macro */
  147. /***********************************************************************/
  148. #ifdef PROTO
  149. short execute_prefix_commands(void)
  150. #else
  151. short execute_prefix_commands()
  152. #endif
  153. /***********************************************************************/
  154. {
  155. /*-------------------------- external data ----------------------------*/
  156.  extern bool readonly;
  157.  extern bool rexx_support;
  158.  extern CHARTYPE number_of_files;
  159.  extern bool curses_started;
  160. /*--------------------------- local data ------------------------------*/
  161.  short cmd_idx=0,rc=RC_OK;
  162.  CHARTYPE cmd[PREFIX_WIDTH+1];
  163.  CHARTYPE mult[PREFIX_WIDTH+1];
  164.  LINETYPE long_mult=0L;
  165.  short top_ppc=0,bot_ppc=0,target_ppc=0;
  166.  PPC *curr_ppc=NULL;
  167.  TARGET target;
  168.  short target_type=TARGET_NORMAL;
  169.  unsigned short y=0,x=0;
  170. /*--------------------------- processing ------------------------------*/
  171. #ifdef TRACE
  172.  trace_function("prefix.c:  execute_prefix_commands");
  173. #endif
  174.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  175.  curr_ppc = CURRENT_FILE->first_ppc;
  176.  while(1)
  177.    {
  178.     if (curr_ppc == NULL)
  179.        break;
  180. /*---------------------------------------------------------------------*/
  181. /* If a set point command, validate the name.                          */
  182. /*---------------------------------------------------------------------*/
  183.     if (*(curr_ppc->ppc_command) == '.')
  184.       {
  185.        if (isalpha(curr_ppc->ppc_command[1]))
  186.          {
  187.           if (execute_set_point(curr_ppc->ppc_command,curr_ppc->ppc_line_number,TRUE) != RC_OK)
  188.             {
  189.              invalidate_prefix(curr_ppc);
  190.              curr_ppc = curr_ppc->next;
  191.              continue;
  192.             }
  193.           clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  194.           curr_ppc = curr_ppc->next;
  195.           continue;
  196.          }
  197.        else
  198.          {
  199.           invalidate_prefix(curr_ppc);
  200.           curr_ppc = curr_ppc->next;
  201.           continue;
  202.          }
  203.       }
  204. /*---------------------------------------------------------------------*/
  205. /* If an invalid prefix command from last time, clear it.              */
  206. /*---------------------------------------------------------------------*/
  207.     if (*(curr_ppc->ppc_command) == '?')
  208.       {
  209.        clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  210.        curr_ppc = curr_ppc->next;
  211.        continue;
  212.       }
  213. /*---------------------------------------------------------------------*/
  214. /* To get here we have 'normal' prefix command.                        */
  215. /*---------------------------------------------------------------------*/
  216.     if (rexx_support)              /* if REXX support is in effect ... */
  217.       {
  218. /*---------------------------------------------------------------------*/
  219. /* first determine if the command is a prefix macro BEFORE looking for */
  220. /* standard prefix commands.                                           */
  221. /*---------------------------------------------------------------------*/
  222.        rc = try_rexx_prefix_macro(curr_ppc);
  223. /*---------------------------------------------------------------------*/
  224. /* If at this point there are no more files in the ring; we assume that*/
  225. /* this was caused by exitting the last file in the ring from a prefix */
  226. /* macro, exit and ignore any more prefix commands. This is messy !!!  */
  227. /*---------------------------------------------------------------------*/
  228.        if (number_of_files == 0)
  229.          {
  230. #ifdef TRACE
  231.           trace_return();
  232. #endif
  233.           return(RC_COMMAND_NO_FILES);
  234.          }
  235.        if (rc != RC_NOT_COMMAND)
  236.          {
  237.           curr_ppc = curr_ppc->next;
  238.           continue;
  239.          }
  240.       }
  241. /*---------------------------------------------------------------------*/
  242. /* if no prefix macro found for the prefix command, check to see if it */
  243. /* is a standard prefix command.                                       */
  244. /*---------------------------------------------------------------------*/
  245.     if ((cmd_idx = parse_prefix_command(curr_ppc,cmd,mult)) == PPC_NO_TARGET)
  246.       {
  247.        invalidate_prefix(curr_ppc);
  248.        curr_ppc = curr_ppc->next;
  249.        continue;
  250.       }
  251.     if (cmd_idx == PPC_NO_COMMAND)
  252.       {
  253.        curr_ppc = curr_ppc->next;
  254.        continue;
  255.       }
  256. /*---------------------------------------------------------------------*/
  257. /* If running in read-only mode and the function selected is not valid */
  258. /* display an error.                                                   */
  259. /*---------------------------------------------------------------------*/
  260.     if (readonly && !pc[cmd_idx].valid_in_readonly)
  261.       {
  262.        display_error(56,"",FALSE);
  263.        invalidate_prefix(curr_ppc);
  264.        continue;
  265.       }
  266. /*---------------------------------------------------------------------*/
  267. /* We now have a recognised command. We have to validate its parameters*/
  268. /* and find any associated pending commands.                           */
  269. /*---------------------------------------------------------------------*/
  270. /*---------------------------------------------------------------------*/
  271. /* Set the block_command flag for the current prefix command to the    */
  272. /* appropriate value for the prefix command.                           */
  273. /*---------------------------------------------------------------------*/
  274.     curr_ppc->ppc_block_command = pc[cmd_idx].block_prefix_command;
  275. /*---------------------------------------------------------------------*/
  276. /* If the command does not allow parameters and there are parameters,  */
  277. /* error.                                                              */
  278. /*---------------------------------------------------------------------*/
  279.     if (!pc[cmd_idx].multiples_allowed
  280.     && strcmp(mult,"") != 0)
  281.       {
  282.        invalidate_prefix(curr_ppc);
  283.        curr_ppc = curr_ppc->next;
  284.        continue;
  285.       }
  286. /*---------------------------------------------------------------------*/
  287. /* If the command does allow parameters and there are no parameters,   */
  288. /* set to default...                                                   */
  289. /*---------------------------------------------------------------------*/
  290.     rc = RC_OK;
  291.     if (strcmp(mult,"") == 0)
  292.        long_mult = pc[cmd_idx].default_target;
  293.     else
  294. /*---------------------------------------------------------------------*/
  295. /* ...otherwise validate the target supplied...                        */
  296. /*---------------------------------------------------------------------*/
  297.       {
  298.        if (pc[cmd_idx].multiples_allowed)
  299.          {
  300.           if (pc[cmd_idx].full_target_allowed)
  301.             {
  302.              initialise_target(&target);
  303.              target.ignore_scope = pc[cmd_idx].ignore_scope;
  304.              if (pc[cmd_idx].use_last_not_in_scope        /* S command */
  305.              && mult[0] == '-')
  306.                 rc = validate_target(mult,&target,target_type,find_last_not_in_scope(NULL,curr_ppc->ppc_line_number,DIRECTION_FORWARD),TRUE,TRUE);
  307.              else
  308.                 rc = validate_target(mult,&target,target_type,curr_ppc->ppc_line_number,TRUE,TRUE);
  309.              if (target.num_lines == 0L)
  310.                 rc = RC_INVALID_OPERAND;
  311.              long_mult = target.num_lines;
  312.              free_target(&target);
  313.             }
  314.           else
  315.              if (!valid_positive_integer(mult))
  316.                 rc = RC_INVALID_OPERAND;
  317.              else
  318.                 long_mult = atol(mult);
  319.          }
  320.       }
  321. /*---------------------------------------------------------------------*/
  322. /* If the target is invalid or not found, invalidate the command.      */
  323. /*---------------------------------------------------------------------*/
  324.     if (rc != RC_OK)
  325.       {
  326.        invalidate_prefix(curr_ppc);
  327.        curr_ppc = curr_ppc->next;
  328.        continue;
  329.       }
  330.     curr_ppc->ppc_cmd_param = long_mult;
  331.     curr_ppc = curr_ppc->next;
  332.    }
  333. /*---------------------------------------------------------------------*/
  334. /* For each valid pending  command for the current view, execute  the  */
  335. /* command.                                                            */
  336. /*---------------------------------------------------------------------*/
  337.  curr_ppc = CURRENT_FILE->first_ppc;
  338.  while(curr_ppc != NULL)
  339.    {
  340.     top_ppc = bot_ppc = target_ppc = (-1);
  341. /*---------------------------------------------------------------------*/
  342. /* Execute the function associated with the prefix command...          */
  343. /*---------------------------------------------------------------------*/
  344.     cmd_idx = curr_ppc->ppc_cmd_idx;
  345.     long_mult = curr_ppc->ppc_cmd_param;
  346.     if (cmd_idx != (-1)
  347.     &&  cmd_idx != (-2)
  348.     &&  pc[cmd_idx].function != NULL)
  349.        rc = (*pc[cmd_idx].function)(curr_ppc,cmd_idx,long_mult);
  350.     curr_ppc = curr_ppc->next;
  351.    }
  352. /*---------------------------------------------------------------------*/
  353. /* The "cleared" pending prefix commands now need to be deleted from   */
  354. /* the linked list...                                                  */
  355. /*---------------------------------------------------------------------*/
  356.  curr_ppc = CURRENT_FILE->first_ppc;
  357.  while(curr_ppc != NULL)
  358.    {
  359.     if (curr_ppc->ppc_cmd_idx == (-1))
  360. #if 0
  361.        curr_ppc = pll_del(&(CURRENT_FILE->first_ppc),&(CURRENT_FILE->last_ppc),curr_ppc,DIRECTION_FORWARD);
  362. #endif
  363.        curr_ppc = delete_pending_prefix_command(curr_ppc,CURRENT_FILE,NULL);
  364.     else
  365.        curr_ppc = curr_ppc->next;
  366.    }
  367. /*---------------------------------------------------------------------*/
  368. /* Now that we are here, display the new version of the screen.        */
  369. /*---------------------------------------------------------------------*/
  370.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  371.  build_current_screen(); 
  372.  display_current_screen();
  373.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  374.    {
  375.     if (curses_started)
  376.        getyx(CURRENT_WINDOW,y,x);
  377.     CURRENT_VIEW->focus_line = get_focus_line_in_view(CURRENT_VIEW->focus_line,y);
  378.     y = get_row_for_focus_line(CURRENT_VIEW->focus_line,CURRENT_VIEW->current_row);
  379.     if (curses_started)
  380.        wmove(CURRENT_WINDOW,y,x);
  381.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  382.    }
  383. #ifdef TRACE
  384.  trace_return();
  385. #endif
  386.  return(RC_OK);
  387. }
  388. /***********************************************************************/
  389. #ifdef PROTO
  390. static short parse_prefix_command(PPC *curr_ppc,CHARTYPE *cmd,CHARTYPE *mult)
  391. #else
  392. static short parse_prefix_command(curr_ppc,cmd,mult)
  393. PPC *curr_ppc;
  394. CHARTYPE *cmd,*mult;
  395. #endif
  396. /***********************************************************************/
  397. {
  398. /*-------------------------- external data ----------------------------*/
  399. /*--------------------------- local data ------------------------------*/
  400.  register short i=0,j=0;
  401.  short len_pcmd=0;
  402.  CHARTYPE pcmd[PREFIX_WIDTH+1];
  403.  short pos=0,rc=RC_OK;
  404.  LINE *curr=NULL;
  405. /*--------------------------- processing ------------------------------*/
  406. #ifdef TRACE
  407.  trace_function("prefix.c:  parse_prefix_command");
  408. #endif
  409. /*---------------------------------------------------------------------*/
  410. /* For each pending prefix command for the current view, execute the   */
  411. /* appropriate command.                                                */
  412. /*---------------------------------------------------------------------*/
  413.  rc = PPC_NO_TARGET;
  414.  strcpy(pcmd,curr_ppc->ppc_command); /* get our own copy to pull apart */
  415.  if (blank_field(pcmd))          /* if prefix command is blank, return */
  416.    {
  417. #ifdef TRACE
  418.     trace_return();
  419. #endif
  420.     return(PPC_NO_COMMAND);
  421.    }
  422.  len_pcmd = strlen(pcmd);
  423. /*---------------------------------------------------------------------*/
  424. /* For each prefix synonym, determine if it exists somewhere in the    */
  425. /* entered prefix command.                                             */
  426. /*---------------------------------------------------------------------*/
  427.  curr = first_prefix_synonym;
  428.  while(1)
  429.    {
  430.     if (curr == NULL)
  431.        break;
  432.     pos = memfind(pcmd,curr->name,len_pcmd,strlen(curr->name),TRUE,FALSE,' ',' ');
  433.     if (pos == (-1))
  434.       {
  435.        curr = curr->next;
  436.        continue;
  437.       }
  438. /*---------------------------------------------------------------------*/
  439. /* Now that a match on synonym is made, determine the original prefix  */
  440. /* command associated with that synonym...                             */
  441. /*---------------------------------------------------------------------*/
  442.     for (i=0;i<NUMBER_PREFIX_COMMANDS;i++)
  443.       {
  444.        if (strcmp(pc[i].cmd,(CHARTYPE *)curr->line) == 0)
  445.          {
  446.           strcpy(cmd,pc[i].cmd);
  447.           for (j=0;j<strlen(curr->name);j++)
  448.              *(pcmd+pos+j) = ' ';
  449.           strtrunc(pcmd);
  450.           strcpy(mult,pcmd);
  451.           curr_ppc->ppc_cmd_idx = i;
  452. #ifdef TRACE
  453.           trace_return();
  454. #endif
  455.           return(i);
  456.          }
  457.       }
  458. /*---------------------------------------------------------------------*/
  459. /* To get here we found a prefix synonym, but no matching original     */
  460. /* command, so return an error.                                        */
  461. /*---------------------------------------------------------------------*/
  462.     curr_ppc->ppc_cmd_idx = (-1);
  463. #ifdef TRACE
  464.     trace_return();
  465. #endif
  466.     return(rc);
  467.    }
  468. /*---------------------------------------------------------------------*/
  469. /* For each valid prefix command,  check to see if a valid command     */
  470. /* exists somewhere in the entered prefix command.                     */
  471. /*---------------------------------------------------------------------*/
  472.  for (i=0;i<NUMBER_PREFIX_COMMANDS;i++)
  473.    {
  474.     pos = memfind(pcmd,pc[i].cmd,len_pcmd,pc[i].cmd_len,TRUE,FALSE,' ',' ');
  475.     if (pos == (-1))
  476.        continue;
  477.     strcpy(cmd,pc[i].cmd);
  478.     for (j=0;j<pc[i].cmd_len;j++)
  479.        *(pcmd+pos+j) = ' ';
  480.     strtrunc(pcmd);
  481.     strcpy(mult,pcmd);
  482.     rc = i;
  483. /*---------------------------------------------------------------------*/
  484. /* Set a flag in ppc[] array to indicate which command is present.     */
  485. /*---------------------------------------------------------------------*/
  486.     curr_ppc->ppc_cmd_idx = i;
  487.     break;
  488.    }
  489. /*---------------------------------------------------------------------*/
  490. /* If command not found, set a flag in ppc[] array to indicate command */
  491. /* is invalid.                                                         */
  492. /*---------------------------------------------------------------------*/
  493.  if (rc == PPC_NO_TARGET)
  494.     curr_ppc->ppc_cmd_idx = (-1);
  495. #ifdef TRACE
  496.  trace_return();
  497. #endif
  498.  return(rc);
  499. }
  500. /***********************************************************************/
  501. #ifdef PROTO
  502. static short prefix_makecurr(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  503. #else
  504. static short prefix_makecurr(curr_ppc,cmd_idx,number_lines)
  505. PPC *curr_ppc;
  506. short cmd_idx;
  507. LINETYPE number_lines;
  508. #endif
  509. /***********************************************************************/
  510. {
  511. /*-------------------------- external data ----------------------------*/
  512. /*--------------------------- local data ------------------------------*/
  513.  LINETYPE top_line = curr_ppc->ppc_line_number;
  514. /*--------------------------- processing ------------------------------*/
  515.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  516.  execute_makecurr(top_line);
  517.  return(0);
  518. }
  519. /***********************************************************************/
  520. #ifdef PROTO
  521. static short prefix_tabline(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  522. #else
  523. static short prefix_tabline(curr_ppc,cmd_idx,number_lines)
  524. PPC *curr_ppc;
  525. short cmd_idx;
  526. LINETYPE number_lines;
  527. #endif
  528. /***********************************************************************/
  529. {
  530. /*-------------------------- external data ----------------------------*/
  531. /*--------------------------- local data ------------------------------*/
  532.  LINETYPE top_line = curr_ppc->ppc_line_number;
  533.  short tab_row = 0;
  534. /*--------------------------- processing ------------------------------*/
  535.  if ((tab_row = get_row_for_focus_line(top_line,(-1))) != (-1))
  536.    {
  537.     CURRENT_VIEW->tab_base = POSITION_TOP;
  538.     CURRENT_VIEW->tab_off = tab_row+1;
  539.     CURRENT_VIEW->tab_on = TRUE;
  540.    }
  541.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  542.  return(0);
  543. }
  544. /***********************************************************************/
  545. #ifdef PROTO
  546. static short prefix_scale(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  547. #else
  548. static short prefix_scale(curr_ppc,cmd_idx,number_lines)
  549. PPC *curr_ppc;
  550. short cmd_idx;
  551. LINETYPE number_lines;
  552. #endif
  553. /***********************************************************************/
  554. {
  555. /*-------------------------- external data ----------------------------*/
  556. /*--------------------------- local data ------------------------------*/
  557.  LINETYPE top_line = curr_ppc->ppc_line_number;
  558.  short scale_row = 0;
  559. /*--------------------------- processing ------------------------------*/
  560.  if ((scale_row = get_row_for_focus_line(top_line,(-1))) != (-1))
  561.    {
  562.     CURRENT_VIEW->scale_base = POSITION_TOP;
  563.     CURRENT_VIEW->scale_off = scale_row+1;
  564.     CURRENT_VIEW->scale_on = TRUE;
  565.    }
  566.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  567.  return(0);
  568. }
  569. /***********************************************************************/
  570. #ifdef PROTO
  571. static short prefix_show(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  572. #else
  573. static short prefix_show(curr_ppc,cmd_idx,number_lines)
  574. PPC *curr_ppc;
  575. short cmd_idx;
  576. LINETYPE number_lines;
  577. #endif
  578. /***********************************************************************/
  579. {
  580. /*-------------------------- external data ----------------------------*/
  581. /*--------------------------- local data ------------------------------*/
  582.  register int i;
  583.  short rc=RC_OK;
  584.  LINETYPE top_line = curr_ppc->ppc_line_number;
  585.  LINETYPE target_line=0L;
  586.  LINE *curr=NULL;
  587.  short direction=DIRECTION_FORWARD;
  588. /*--------------------------- processing ------------------------------*/
  589.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  590.  if (TOF(top_line)
  591.  ||  BOF(top_line))
  592.     return(-1);
  593. /*---------------------------------------------------------------------*/
  594. /* Find the current line from where we start showing...                */
  595. /*---------------------------------------------------------------------*/
  596.  curr = lll_find(CURRENT_FILE->first_line,top_line);
  597. /*---------------------------------------------------------------------*/
  598. /* If the line that the show command was entered is in scope, then     */
  599. /* return with an error.                                               */
  600. /*---------------------------------------------------------------------*/
  601.  if (in_scope(curr))
  602.    {
  603.     invalidate_prefix(curr_ppc);
  604.     return(-1);
  605.    }
  606. /*---------------------------------------------------------------------*/
  607. /* For a negative target, show the lines from the end of the excluded  */
  608. /* block.                                                              */
  609. /*---------------------------------------------------------------------*/
  610.  if (number_lines < 0)
  611.    {
  612.     target_line = find_last_not_in_scope(curr,top_line,DIRECTION_FORWARD);
  613.     curr = lll_find(CURRENT_FILE->first_line,target_line);
  614.     for(i=0;i>number_lines;i--)
  615.       {
  616.        curr->select = CURRENT_VIEW->display_high;
  617.        curr = curr->prev;
  618.        if (curr->prev == NULL
  619.        ||  in_scope(curr))
  620.           break;
  621.       }
  622.    }
  623.  else
  624. /*---------------------------------------------------------------------*/
  625. /* For a positive target, show the lines from the start of the excluded*/
  626. /* block.                                                              */
  627. /*---------------------------------------------------------------------*/
  628.    {
  629.     for(i=0;i<number_lines;i++)
  630.       {
  631.        curr->select = CURRENT_VIEW->display_high;
  632.        curr = curr->next;
  633.        if (curr->next == NULL
  634.        ||  in_scope(curr))
  635.           break;
  636.       }
  637.    }
  638.  return(rc);
  639. }
  640. /***********************************************************************/
  641. #ifdef PROTO
  642. static short prefix_exclude(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  643. #else
  644. static short prefix_exclude(curr_ppc,cmd_idx,number_lines)
  645. PPC *curr_ppc;
  646. short cmd_idx;
  647. LINETYPE number_lines;
  648. #endif
  649. /***********************************************************************/
  650. {
  651. /*-------------------------- external data ----------------------------*/
  652. /*--------------------------- local data ------------------------------*/
  653.  short rc=RC_OK;
  654.  LINETYPE top_line = curr_ppc->ppc_line_number;
  655.  LINE *curr=NULL;
  656.  short direction=DIRECTION_FORWARD;
  657. /*--------------------------- processing ------------------------------*/
  658.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  659.  if (TOF(top_line)
  660.  ||  BOF(top_line))
  661.     return(-1);
  662. /*---------------------------------------------------------------------*/
  663. /* If the high value of SET DISPLAY is 255, we can't exclude any lines */
  664. /* so exit.                                                            */
  665. /*---------------------------------------------------------------------*/
  666.  if (CURRENT_VIEW->display_high == 255)
  667.     return(rc);
  668.  if (number_lines < 0)
  669.     direction = DIRECTION_BACKWARD;
  670.  else
  671.     direction = DIRECTION_FORWARD;
  672. /*---------------------------------------------------------------------*/
  673. /* Find the current line from where we start excluding...              */
  674. /*---------------------------------------------------------------------*/
  675.  curr = lll_find(CURRENT_FILE->first_line,top_line);
  676. /*---------------------------------------------------------------------*/
  677. /* For the number of lines affected, change the select level if the    */
  678. /* line is in scope.                                                   */
  679. /*---------------------------------------------------------------------*/
  680.  while(number_lines != 0)
  681.    {
  682.     if (in_scope(curr))
  683.        curr->select = (short)CURRENT_VIEW->display_high + 1;
  684.     if (direction == DIRECTION_FORWARD)
  685.        curr = curr->next;
  686.     else
  687.        curr = curr->prev;
  688.     number_lines -= direction;
  689.    }
  690.  return(rc);
  691. }
  692. /***********************************************************************/
  693. #ifdef PROTO
  694. static short prefix_add(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  695. #else
  696. static short prefix_add(curr_ppc,cmd_idx,number_lines)
  697. PPC *curr_ppc;
  698. short cmd_idx;
  699. LINETYPE number_lines;
  700. #endif
  701. /***********************************************************************/
  702. {
  703. /*-------------------------- external data ----------------------------*/
  704. /*--------------------------- local data ------------------------------*/
  705.  short rc=(-1);
  706.  LINETYPE top_line = curr_ppc->ppc_line_number;
  707. /*--------------------------- processing ------------------------------*/
  708.  if (top_line == CURRENT_FILE->number_lines+1)
  709.     top_line--;
  710.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  711.  rc = insert_new_line((CHARTYPE *)"",0,number_lines,
  712.                      top_line,FALSE,FALSE,CURRENT_VIEW->display_low);
  713.  return(rc);
  714. }
  715. /***********************************************************************/
  716. #ifdef PROTO
  717. static short prefix_duplicate(PPC *curr_ppc,short cmd_idx,LINETYPE number_occ)
  718. #else
  719. static short prefix_duplicate(curr_ppc,cmd_idx,number_occ)
  720. PPC *curr_ppc;
  721. short cmd_idx;
  722. LINETYPE number_occ;
  723. #endif
  724. /***********************************************************************/
  725. {
  726. /*-------------------------- external data ----------------------------*/
  727. /*--------------------------- local data ------------------------------*/
  728.  short rc=(-1);
  729.  LINETYPE top_line = curr_ppc->ppc_line_number;
  730. /*--------------------------- processing ------------------------------*/
  731.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  732.  if (top_line != 0L
  733.  &&  top_line != CURRENT_FILE->number_lines+1)
  734.     rc = rearrange_line_blocks(COMMAND_DUPLICATE,SOURCE_PREFIX,top_line,top_line,top_line,(short)number_occ,CURRENT_VIEW,CURRENT_VIEW,TRUE);
  735.  return(rc);
  736. }
  737. /***********************************************************************/
  738. #ifdef PROTO
  739. static short prefix_copy(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  740. #else
  741. static short prefix_copy(curr_ppc,cmd_idx,number_lines)
  742. PPC *curr_ppc;
  743. short cmd_idx;
  744. LINETYPE number_lines;
  745. #endif
  746. /***********************************************************************/
  747. {
  748. /*-------------------------- external data ----------------------------*/
  749. /*--------------------------- local data ------------------------------*/
  750.  LINETYPE bottom_line=0L,target_line=0L;
  751.  LINETYPE top_line = curr_ppc->ppc_line_number;
  752.  PPC *target_ppc=NULL;
  753.  short rc=(-1);
  754. /*--------------------------- processing ------------------------------*/
  755.  if ((target_ppc = calculate_target_line()) == NULL)
  756.     return(rc);
  757.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  758.  bottom_line = top_line + number_lines - ((number_lines < 0L) ? (-1L) : 1L);
  759.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  760.  if (top_line != 0L
  761.  &&  top_line != CURRENT_FILE->number_lines+1)
  762.     rc = rearrange_line_blocks(COMMAND_COPY,SOURCE_PREFIX,top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE);
  763.  return(rc);
  764. }
  765. /***********************************************************************/
  766. #ifdef PROTO
  767. static short prefix_move(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  768. #else
  769. static short prefix_move(curr_ppc,cmd_idx,number_lines)
  770. PPC *curr_ppc;
  771. short cmd_idx;
  772. LINETYPE number_lines;
  773. #endif
  774. /***********************************************************************/
  775. {
  776. /*-------------------------- external data ----------------------------*/
  777. /*--------------------------- local data ------------------------------*/
  778.  LINETYPE bottom_line=0L,target_line=0L;
  779.  LINETYPE top_line = curr_ppc->ppc_line_number;
  780.  PPC *target_ppc=NULL;
  781.  short rc=(-1);
  782. /*--------------------------- processing ------------------------------*/
  783.  if ((target_ppc = calculate_target_line()) == NULL)
  784.     return(rc);
  785.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  786.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  787.  bottom_line = top_line + number_lines - ((number_lines < 0L) ? (-1L) : 1L);
  788.  
  789.  if (top_line != 0L
  790.  &&  top_line != CURRENT_FILE->number_lines+1)
  791.    {
  792.     if ((rc = rearrange_line_blocks(COMMAND_MOVE_COPY_SAME,SOURCE_PREFIX,
  793.          top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE)) != RC_OK)
  794.        return(rc);
  795.     if (target_line < top_line)
  796.       {
  797.        top_line += number_lines;
  798.        target_line += number_lines;
  799.        bottom_line += number_lines;
  800.       }
  801.     rc = rearrange_line_blocks(COMMAND_MOVE_DELETE_SAME,SOURCE_PREFIX,
  802.          top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE);
  803.    }
  804.  return(rc);
  805. }
  806. /***********************************************************************/
  807. #ifdef PROTO
  808. static short prefix_delete(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  809. #else
  810. static short prefix_delete(curr_ppc,cmd_idx,number_lines)
  811. PPC *curr_ppc;
  812. short cmd_idx;
  813. LINETYPE number_lines;
  814. #endif
  815. /***********************************************************************/
  816. {
  817. /*-------------------------- external data ----------------------------*/
  818. /*--------------------------- local data ------------------------------*/
  819.  short rc=(-1);
  820.  LINETYPE top_line = curr_ppc->ppc_line_number;
  821.  LINETYPE bottom_line=0L,target_line=0L;
  822. /*--------------------------- processing ------------------------------*/
  823.  
  824.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  825.  if (!TOF(top_line)
  826.  &&  !BOF(top_line))
  827.    {
  828.     bottom_line = top_line + number_lines - ((number_lines < 0L) ? (-1L) : 1L);
  829.     target_line = (number_lines < 0L) ? (bottom_line) : (top_line);
  830.     rc = rearrange_line_blocks(COMMAND_DELETE,SOURCE_PREFIX,top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,TRUE);
  831.    }
  832.  return(rc);
  833. }
  834. /***********************************************************************/
  835. #ifdef PROTO
  836. static short prefix_shift_left(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  837. #else
  838. static short prefix_shift_left(curr_ppc,cmd_idx,number_cols)
  839. PPC *curr_ppc;
  840. short cmd_idx;
  841. LINETYPE number_cols;
  842. #endif
  843. /***********************************************************************/
  844. {
  845. /*-------------------------- external data ----------------------------*/
  846. /*--------------------------- local data ------------------------------*/
  847.  LINETYPE top_line = curr_ppc->ppc_line_number;
  848. /*--------------------------- processing ------------------------------*/
  849.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  850.  if (top_line != 0L
  851.  &&  top_line != CURRENT_FILE->number_lines+1)
  852.    {
  853.     execute_shift_command(TRUE,(short)number_cols,top_line,1L,TRUE);
  854.    }
  855.  return(0);
  856. }
  857. /***********************************************************************/
  858. #ifdef PROTO
  859. static short prefix_shift_right(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  860. #else
  861. static short prefix_shift_right(curr_ppc,cmd_idx,number_cols)
  862. PPC *curr_ppc;
  863. short cmd_idx;
  864. LINETYPE number_cols;
  865. #endif
  866. /***********************************************************************/
  867. {
  868. /*-------------------------- external data ----------------------------*/
  869. /*--------------------------- local data ------------------------------*/
  870.  LINETYPE start_line = curr_ppc->ppc_line_number;
  871. /*--------------------------- processing ------------------------------*/
  872.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  873.  if (start_line != 0L
  874.  &&  start_line != CURRENT_FILE->number_lines+1)
  875.    {
  876.     execute_shift_command(FALSE,(short)number_cols,start_line,1L,TRUE);
  877.    }
  878.  return(0);
  879. }
  880. /***********************************************************************/
  881. #ifdef PROTO
  882. static short prefix_block_duplicate(PPC *curr_ppc,short cmd_idx,LINETYPE number_occ)
  883. #else
  884. static short prefix_block_duplicate(curr_ppc,cmd_idx,number_occ)
  885. PPC *curr_ppc;
  886. short cmd_idx;
  887. LINETYPE number_occ;
  888. #endif
  889. /***********************************************************************/
  890. {
  891. /*-------------------------- external data ----------------------------*/
  892. /*--------------------------- local data ------------------------------*/
  893.  short rc=(-1);
  894.  LINETYPE top_line=0L,bottom_line=0L;
  895.  PPC *bottom_ppc=NULL;
  896. /*--------------------------- processing ------------------------------*/
  897.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  898.     return(rc);
  899.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  900.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  901.  top_line = (top_line == 0L) ? 1L : top_line;
  902.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  903.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  904.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  905.  rc = rearrange_line_blocks(COMMAND_DUPLICATE,SOURCE_PREFIX,top_line,bottom_line,bottom_line,(short)number_occ,CURRENT_VIEW,CURRENT_VIEW,FALSE);
  906.  return(rc);
  907. }
  908. /***********************************************************************/
  909. #ifdef PROTO
  910. static short prefix_block_copy(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  911. #else
  912. static short prefix_block_copy(curr_ppc,cmd_idx,number_lines)
  913. PPC *curr_ppc;
  914. short cmd_idx;
  915. LINETYPE number_lines;
  916. #endif
  917. /***********************************************************************/
  918. {
  919. /*-------------------------- external data ----------------------------*/
  920. /*--------------------------- local data ------------------------------*/
  921.  short rc=(-1);
  922.  LINETYPE top_line=0L,bottom_line=0L,target_line=0L;
  923.  PPC *bottom_ppc=NULL;
  924.  PPC *target_ppc=NULL;
  925. /*--------------------------- processing ------------------------------*/
  926.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  927.     return(rc);
  928.  if ((target_ppc = calculate_target_line()) == NULL)
  929.     return(rc);
  930.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  931.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  932.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  933.  top_line = (top_line == 0L) ? 1L : top_line;
  934.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  935.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  936.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  937.  rc = rearrange_line_blocks(COMMAND_COPY,SOURCE_PREFIX,top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE);
  938.  return(rc);
  939. }
  940. /***********************************************************************/
  941. #ifdef PROTO
  942. static short prefix_block_move(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  943. #else
  944. static short prefix_block_move(curr_ppc,cmd_idx,number_lines)
  945. PPC *curr_ppc;
  946. short cmd_idx;
  947. LINETYPE number_lines;
  948. #endif
  949. /***********************************************************************/
  950. {
  951. /*-------------------------- external data ----------------------------*/
  952. /*--------------------------- local data ------------------------------*/
  953.  short rc=(-1);
  954.  LINETYPE top_line=0L,bottom_line=0L,target_line=0L,num_lines=0L;
  955.  PPC *bottom_ppc=NULL;
  956.  PPC *target_ppc=NULL;
  957. /*--------------------------- processing ------------------------------*/
  958.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  959.     return(rc);
  960.  if ((target_ppc = calculate_target_line()) == NULL)
  961.     return(rc);
  962.  target_line = target_ppc->ppc_line_number+target_ppc->ppc_cmd_param;
  963.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  964.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  965.  top_line = (top_line == 0L) ? 1L : top_line;
  966.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  967.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  968.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  969.  if ((rc = rearrange_line_blocks(COMMAND_MOVE_COPY_SAME,SOURCE_PREFIX,
  970.            top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE)) != RC_OK)
  971.     return(rc);
  972.  if (target_line < top_line)
  973.    {
  974.     num_lines = bottom_line - top_line + 1L;
  975.     top_line += num_lines;
  976.     bottom_line += num_lines;
  977.     target_line += num_lines;
  978.    }
  979.  rc = rearrange_line_blocks(COMMAND_MOVE_DELETE_SAME,SOURCE_PREFIX,
  980.       top_line,bottom_line,target_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE);
  981.  return(rc);
  982. }
  983. /***********************************************************************/
  984. #ifdef PROTO
  985. static short prefix_block_delete(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  986. #else
  987. static short prefix_block_delete(curr_ppc,cmd_idx,number_lines)
  988. PPC *curr_ppc;
  989. short cmd_idx;
  990. LINETYPE number_lines;
  991. #endif
  992. /***********************************************************************/
  993. {
  994. /*-------------------------- external data ----------------------------*/
  995. /*--------------------------- local data ------------------------------*/
  996.  short rc=(-1);
  997.  LINETYPE top_line=0L,bottom_line=0L;
  998.  PPC *bottom_ppc=NULL;
  999. /*--------------------------- processing ------------------------------*/
  1000.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1001.     return(rc);
  1002.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1003.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1004.  top_line = (top_line == 0L) ? 1L : top_line;
  1005.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1006.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1007.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1008.  rc = rearrange_line_blocks(COMMAND_DELETE,SOURCE_PREFIX,top_line,bottom_line,bottom_line,1,CURRENT_VIEW,CURRENT_VIEW,FALSE);
  1009.  return(rc);
  1010. }
  1011. /***********************************************************************/
  1012. #ifdef PROTO
  1013. static short prefix_block_shift_left(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  1014. #else
  1015. static short prefix_block_shift_left(curr_ppc,cmd_idx,number_cols)
  1016. PPC *curr_ppc;
  1017. short cmd_idx;
  1018. LINETYPE number_cols;
  1019. #endif
  1020. /***********************************************************************/
  1021. {
  1022. /*-------------------------- external data ----------------------------*/
  1023. /*--------------------------- local data ------------------------------*/
  1024.  LINETYPE top_line=0L,bottom_line=0L;
  1025.  PPC *bottom_ppc;
  1026. /*--------------------------- processing ------------------------------*/
  1027.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1028.     return(-1);
  1029.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1030.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1031.  
  1032.  top_line = (top_line == 0L) ? 1L : top_line;
  1033.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1034.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1035.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1036.  
  1037.  execute_shift_command(TRUE,(short)number_cols,top_line,bottom_line-top_line+1L,FALSE);
  1038.  
  1039.  return(0);
  1040. }
  1041. /***********************************************************************/
  1042. #ifdef PROTO
  1043. static short prefix_block_shift_right(PPC *curr_ppc,short cmd_idx,LINETYPE number_cols)
  1044. #else
  1045. static short prefix_block_shift_right(curr_ppc,cmd_idx,number_cols)
  1046. PPC *curr_ppc;
  1047. short cmd_idx;
  1048. LINETYPE number_cols;
  1049. #endif
  1050. /***********************************************************************/
  1051. {
  1052. /*-------------------------- external data ----------------------------*/
  1053. /*--------------------------- local data ------------------------------*/
  1054.  LINETYPE top_line=0L,bottom_line=0L;
  1055.  PPC *bottom_ppc=NULL;
  1056. /*--------------------------- processing ------------------------------*/
  1057.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1058.     return(-1);
  1059.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1060.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1061.  
  1062.  top_line = (top_line == 0L) ? 1L : top_line;
  1063.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1064.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1065.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1066.  
  1067.  execute_shift_command(FALSE,(short)number_cols,top_line,bottom_line-top_line+1L,FALSE);
  1068.  
  1069.  return(0);
  1070. }
  1071. /***********************************************************************/
  1072. #ifdef PROTO
  1073. static short prefix_block_exclude(PPC *curr_ppc,short cmd_idx,LINETYPE number_lines)
  1074. #else
  1075. static short prefix_block_exclude(curr_ppc,cmd_idx,number_lines)
  1076. PPC *curr_ppc;
  1077. short cmd_idx;
  1078. LINETYPE number_lines;
  1079. #endif
  1080. /***********************************************************************/
  1081. {
  1082. /*-------------------------- external data ----------------------------*/
  1083. /*--------------------------- local data ------------------------------*/
  1084.  short rc=RC_OK;
  1085.  LINETYPE top_line=0L,bottom_line=0L,num_lines=0L,i=0L;
  1086.  LINE *curr=NULL;
  1087.  PPC *bottom_ppc=NULL;
  1088. /*--------------------------- processing ------------------------------*/
  1089.  if ((bottom_ppc = find_bottom_ppc(curr_ppc,cmd_idx)) == NULL)
  1090.     return(-1);
  1091.  top_line = min(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1092.  bottom_line = max(curr_ppc->ppc_line_number,bottom_ppc->ppc_line_number);
  1093.  top_line = (top_line == 0L) ? 1L : top_line;
  1094.  bottom_line = (bottom_line == CURRENT_FILE->number_lines+1L) ? bottom_line-1L : bottom_line;
  1095.  num_lines = bottom_line-top_line+1L;
  1096.  clear_pending_prefix_command(curr_ppc,(LINE *)NULL);
  1097.  clear_pending_prefix_command(bottom_ppc,(LINE *)NULL);
  1098. /*---------------------------------------------------------------------*/
  1099. /* If the high value of SET DISPLAY is 255, we can't exclude any lines */
  1100. /* so exit.                                                            */
  1101. /*---------------------------------------------------------------------*/
  1102.  if (CURRENT_VIEW->display_high == 255)
  1103.     return(rc);
  1104. /*---------------------------------------------------------------------*/
  1105. /* Find the current line from where we start excluding...              */
  1106. /*---------------------------------------------------------------------*/
  1107.  curr = lll_find(CURRENT_FILE->first_line,top_line);
  1108. /*---------------------------------------------------------------------*/
  1109. /* For the number of lines affected, change the select level if the    */
  1110. /* line is in scope.                                                   */
  1111. /*---------------------------------------------------------------------*/
  1112.  for (i=0;i<num_lines;i++)
  1113.    {
  1114.     if (in_scope(curr))
  1115.        curr->select = (short)CURRENT_VIEW->display_high + 1;
  1116.     curr = curr->next;
  1117.    }
  1118.  return(rc);
  1119. }
  1120. /***********************************************************************/
  1121. #ifdef PROTO
  1122. static short invalidate_prefix(PPC *curr_ppc)
  1123. #else
  1124. static short invalidate_prefix(curr_ppc)
  1125. PPC *curr_ppc;
  1126. #endif
  1127. /***********************************************************************/
  1128. {
  1129. /*-------------------------- external data ----------------------------*/
  1130.  extern short prefix_width;
  1131. /*--------------------------- local data ------------------------------*/
  1132.  short len=0;
  1133. /*--------------------------- processing ------------------------------*/
  1134.  if (*(curr_ppc->ppc_command) != '?')
  1135.    {
  1136.     len = strlen(curr_ppc->ppc_command);
  1137.     meminschr(curr_ppc->ppc_command,'?',0,prefix_width,len);
  1138.     *(curr_ppc->ppc_command+len+1) = '\0';
  1139.    }
  1140. /*---------------------------------------------------------------------*/
  1141. /* ensure that there is no chance that a 'real' prefix command can be  */
  1142. /* executed.                                                           */
  1143. /*---------------------------------------------------------------------*/
  1144.  curr_ppc->ppc_cmd_idx = (-2);
  1145.  return(RC_OK);
  1146. }
  1147. /***********************************************************************/
  1148. #ifdef PROTO
  1149. void clear_pending_prefix_command(PPC *curr_ppc,LINE *curr_line)
  1150. #else
  1151. void clear_pending_prefix_command(curr_ppc,curr_line)
  1152. PPC *curr_ppc;
  1153. LINE *curr_line;
  1154. #endif
  1155. /***********************************************************************/
  1156. {
  1157. /*-------------------------- external data ----------------------------*/
  1158. /*--------------------------- local data ------------------------------*/
  1159.  LINE *curr=curr_line;
  1160. /*--------------------------- processing ------------------------------*/
  1161. /*---------------------------------------------------------------------*/
  1162. /* If curr_ppc == NULL, then do nothing.                               */
  1163. /*---------------------------------------------------------------------*/
  1164.  if (curr_ppc == NULL)
  1165.     return;
  1166.  if (curr == (LINE *)NULL)
  1167.     curr = lll_find(CURRENT_FILE->first_line,curr_ppc->ppc_line_number);
  1168.  curr->pre = NULL;
  1169.  curr_ppc->ppc_cmd_idx = (-1);
  1170.  curr_ppc->ppc_block_command = FALSE;
  1171.  return;
  1172. }
  1173. /***********************************************************************/
  1174. #ifdef PROTO
  1175. PPC *delete_pending_prefix_command(PPC *curr_ppc,FILE_DETAILS *curr_file,LINE *curr_line)
  1176. #else
  1177. PPC *delete_pending_prefix_command(curr_ppc,curr_file,curr_line)
  1178. PPC *curr_ppc;
  1179. FILE_DETAILS *curr_file;
  1180. LINE *curr_line;
  1181. #endif
  1182. /***********************************************************************/
  1183. {
  1184. /*-------------------------- external data ----------------------------*/
  1185. /*--------------------------- local data ------------------------------*/
  1186.  LINE *curr=curr_line;
  1187.  PPC *return_ppc=NULL;
  1188. /*--------------------------- processing ------------------------------*/
  1189. /*---------------------------------------------------------------------*/
  1190. /* If curr_ppc == NULL, then do nothing.                               */
  1191. /*---------------------------------------------------------------------*/
  1192.  if (curr_ppc == NULL)
  1193.     return(NULL);
  1194.  if (curr == (LINE *)NULL)
  1195.     curr = lll_find(curr_file->first_line,curr_ppc->ppc_line_number);
  1196.  curr->pre = NULL;
  1197.  return_ppc = pll_del(&(curr_file->first_ppc),&(curr_file->last_ppc),curr_ppc,DIRECTION_FORWARD);
  1198.  return(return_ppc);
  1199. }
  1200. /***********************************************************************/
  1201. #ifdef PROTO
  1202. static PPC *find_bottom_ppc(PPC *curr_ppc,short top_cmd_idx)
  1203. #else
  1204. static PPC *find_bottom_ppc(curr_ppc,top_cmd_idx)
  1205. PPC *curr_ppc;
  1206. short top_cmd_idx;
  1207. #endif
  1208. /***********************************************************************/
  1209. {
  1210. /*-------------------------- external data ----------------------------*/
  1211. /*--------------------------- local data ------------------------------*/
  1212.  PPC *bottom_ppc=curr_ppc;
  1213. /*--------------------------- processing ------------------------------*/
  1214.  while(bottom_ppc != NULL)
  1215.    {
  1216.     if (bottom_ppc != curr_ppc)
  1217.       {
  1218.        if (top_cmd_idx == curr_ppc->ppc_cmd_idx)
  1219.           return(bottom_ppc);
  1220.       }
  1221.     bottom_ppc = bottom_ppc->next;
  1222.    }
  1223.  return(NULL);
  1224. }
  1225. /***********************************************************************/
  1226. #ifdef PROTO
  1227. static PPC *find_target_ppc(void)
  1228. #else
  1229. static PPC *find_target_ppc()
  1230. #endif
  1231. /***********************************************************************/
  1232. {
  1233. /*-------------------------- external data ----------------------------*/
  1234. /*--------------------------- local data ------------------------------*/
  1235.  PPC *target_ppc=NULL;
  1236. /*--------------------------- processing ------------------------------*/
  1237.  target_ppc = CURRENT_FILE->first_ppc;
  1238.  while(target_ppc != NULL)
  1239.    {
  1240.     if (target_ppc->ppc_cmd_idx == PPC_TARGET_PREVIOUS
  1241.     ||  target_ppc->ppc_cmd_idx == PPC_TARGET_FOLLOWING)
  1242.        return(target_ppc);
  1243.     target_ppc = target_ppc->next;
  1244.    }
  1245.  return(NULL);
  1246. }
  1247. /***********************************************************************/
  1248. #ifdef PROTO
  1249. static PPC *calculate_target_line(void)
  1250. #else
  1251. static PPC *calculate_target_line()
  1252. #endif
  1253. /***********************************************************************/
  1254. {
  1255. /*-------------------------- external data ----------------------------*/
  1256. /*--------------------------- local data ------------------------------*/
  1257.  PPC *target_ppc=NULL;
  1258. /*--------------------------- processing ------------------------------*/
  1259.  if ((target_ppc = find_target_ppc()) == NULL)
  1260.     return(NULL);
  1261.  target_ppc->ppc_cmd_param = 0L;
  1262. /*---------------------------------------------------------------------*/
  1263. /* If the target line is NOT top of file line and the target type is   */
  1264. /* PREVIOUS, subtract 1 from the target line.                          */
  1265. /*---------------------------------------------------------------------*/
  1266.  if (target_ppc->ppc_cmd_idx == PPC_TARGET_PREVIOUS
  1267.  && !TOF(target_ppc->ppc_line_number))
  1268.     target_ppc->ppc_cmd_param = (-1);
  1269. /*---------------------------------------------------------------------*/
  1270. /* If the target line is the bottom of file and the target type is     */
  1271. /* FOLLOWING, sutract 1 from the target line.                          */
  1272. /*---------------------------------------------------------------------*/
  1273.  if (target_ppc->ppc_cmd_idx == PPC_TARGET_FOLLOWING
  1274.  && BOF(target_ppc->ppc_line_number))
  1275.     target_ppc->ppc_cmd_param = (-1);
  1276.  clear_pending_prefix_command(target_ppc,(LINE *)NULL);
  1277.  return(target_ppc);
  1278. }
  1279. /***********************************************************************/
  1280. #ifdef PROTO
  1281. static short try_rexx_prefix_macro(PPC *curr_ppc)
  1282. #else
  1283. static short try_rexx_prefix_macro(curr_ppc)
  1284. PPC *curr_ppc;
  1285. #endif
  1286. /***********************************************************************/
  1287. {
  1288. /*-------------------------- external data ----------------------------*/
  1289.  extern CHARTYPE *temp_cmd;
  1290. /*--------------------------- local data ------------------------------*/
  1291.  short ctr=0, parm_length=0, pmacro_rc=0, errnum = 0 ;
  1292.  bool found_left=FALSE, found_right=FALSE;
  1293.  LINETYPE line_number=0L;
  1294.  CHARTYPE pm_parms[(PREFIX_WIDTH*4)+1], t_area[PREFIX_WIDTH+1],
  1295.       parms[PREFIX_WIDTH+1], tmpstr[PREFIX_WIDTH+1], 
  1296.       orig_cmd[PREFIX_WIDTH+1];
  1297. /*--------------------------- processing ------------------------------*/
  1298.  strcpy(orig_cmd, curr_ppc->ppc_command);
  1299.  
  1300.  found_right = FALSE;
  1301.  found_left = FALSE;
  1302. /*---------------------------------------------------------------------*/
  1303. /* Scan 'orig_cmd' from right to left looking for an embedded macro    */
  1304. /* file name.                                                          */
  1305. /*---------------------------------------------------------------------*/
  1306.  for (ctr = strlen(orig_cmd); ctr >= 0 && !found_right; ctr--)
  1307.    {
  1308.     substr(&tmpstr[0], orig_cmd, 1, ctr);
  1309.     strcpy(t_area, tmpstr);
  1310. /*---------------------------------------------------------------------*/
  1311. /* First check if the prefix command is a synonym.                     */
  1312. /*---------------------------------------------------------------------*/
  1313. /* check for prefix synonym, if so use the macro name not the synonym */
  1314.     get_valid_macro_file_name(find_prefix_synonym(t_area),temp_cmd,&errnum);
  1315.  
  1316.     if (errnum == 0)
  1317.        found_right = TRUE;
  1318.    }
  1319.  
  1320. /*---------------------------------------------------------------------*/
  1321. /* No valid macro file name found ?                                    */
  1322. /*                                                                     */
  1323. /* Scan 'temp_cmd' from left to right looking for an embedded macro    */
  1324. /* file name.                                                          */
  1325. /*---------------------------------------------------------------------*/
  1326.  if (!found_right)
  1327.    for ( ctr = 0; ctr <= strlen(orig_cmd) && !found_left; ctr++)
  1328.      {
  1329.       substr(&tmpstr[0], orig_cmd, ctr + 1, strlen(temp_cmd) - ctr);
  1330.       strcpy(t_area, tmpstr);
  1331. /*---------------------------------------------------------------------*/
  1332. /* First check if the prefix command is a synonym.                     */
  1333. /*---------------------------------------------------------------------*/
  1334. /* check for prefix synonym, if so use the macro name not the synonym */
  1335.       get_valid_macro_file_name(find_prefix_synonym(t_area),temp_cmd,&errnum);
  1336.  
  1337.       if (errnum == 0)
  1338.          found_left = TRUE;
  1339.      }
  1340.  
  1341.  if (found_right || found_left)
  1342.    {
  1343.     parm_length = strlen(orig_cmd) - strlen(t_area);
  1344.  
  1345.     if (found_right)
  1346.        substr(&tmpstr[0],orig_cmd,strlen(t_area) + 1,parm_length);
  1347.     else
  1348.        substr(&tmpstr[0],orig_cmd,1,parm_length);
  1349.  
  1350.     strcpy(parms, tmpstr);
  1351.     line_number = curr_ppc->ppc_line_number;
  1352.     sprintf(pm_parms," PREFIX %ld %s",line_number,parms);
  1353.     strcat(temp_cmd, pm_parms);     /* add on the parameter list */
  1354.     prefix_current_line = line_number;
  1355.     in_prefix_macro = TRUE;
  1356.     pmacro_rc = execute_macro(temp_cmd,TRUE);
  1357.     in_prefix_macro = FALSE;
  1358.    }
  1359.  else
  1360.     pmacro_rc = RC_NOT_COMMAND;
  1361.  
  1362.  return(pmacro_rc);
  1363. }
  1364. /***********************************************************************/
  1365. #ifdef PROTO
  1366. static CHARTYPE *substr(CHARTYPE *temp_string,CHARTYPE *string,short start,short length)
  1367. #else
  1368. static CHARTYPE *substr(temp_string, string, start, length)
  1369. CHARTYPE *temp_string, *string;
  1370. short start, length;
  1371. #endif
  1372. /***********************************************************************/
  1373. /* This function is like the REXX SUBSTR function, it returns a        */
  1374. /* pointer to a string containing the result.                          */
  1375. /* Note: The address of the beginning of a blank string is passed to be*/
  1376. /* modified by address: substr(&tmpstr[0],<string>,<start>,<length>);  */
  1377. /* ( In this case, the result is contained in 'tmpstr'  :-)            */
  1378. /***********************************************************************/
  1379. {
  1380. /*-------------------------- external data ----------------------------*/
  1381. /*--------------------------- local data ------------------------------*/
  1382.  register i=0, target_idx = 0;
  1383. /*--------------------------- processing ------------------------------*/
  1384.  for (i = start - 1; target_idx <= length - 1; i++)
  1385.     temp_string[target_idx++] = string[i];
  1386.  temp_string[target_idx] = '\0';   /*MH*/
  1387.  return(temp_string);
  1388. }
  1389. /***********************************************************************/
  1390. #ifdef PROTO
  1391. void add_prefix_command(LINE *curr,LINETYPE line_number,bool block_command)
  1392. #else
  1393. void add_prefix_command(curr,line_number,block_command)
  1394. LINE *curr;
  1395. LINETYPE line_number;
  1396. bool block_command;
  1397. #endif
  1398. /***********************************************************************/
  1399. {
  1400. /*------------------------- external data -----------------------------*/
  1401.  extern bool prefix_changed;
  1402.  extern CHARTYPE *pre_rec;
  1403.  extern unsigned short pre_rec_len;
  1404. /*--------------------------- local data ------------------------------*/
  1405.  register short i=0;
  1406.  short prefix_index=0;
  1407.  CHARTYPE temp_prefix_array[PREFIX_WIDTH+1];
  1408.  PPC *curr_ppc=NULL;
  1409.  bool redisplay_screen=FALSE;
  1410. /*--------------------------- processing ------------------------------*/
  1411. #ifdef TRACE
  1412.  trace_function("prefix.c:  add_prefix_command");
  1413. #endif
  1414.  prefix_changed = FALSE;
  1415. /*---------------------------------------------------------------------*/
  1416. /* Copy the contexts of the prefix record area into a temporary area.  */
  1417. /*---------------------------------------------------------------------*/
  1418.  for (i=0;i<pre_rec_len;i++)
  1419.      temp_prefix_array[i] = pre_rec[i];
  1420.  temp_prefix_array[pre_rec_len] = '\0';
  1421.  strtrunc(temp_prefix_array);
  1422. /*---------------------------------------------------------------------*/
  1423. /* If the prefix record area is blank, clear the pending prefix area.  */
  1424. /*---------------------------------------------------------------------*/
  1425.  if (blank_field(temp_prefix_array))
  1426.    {
  1427.     (void)delete_pending_prefix_command(curr->pre,CURRENT_FILE,curr);
  1428.     redisplay_screen = TRUE;
  1429.    }
  1430.  else
  1431.    {
  1432. /*---------------------------------------------------------------------*/
  1433. /* If the input line already points to an entry in the array, use the  */
  1434. /* existing entry in the array, otherwise add to the next entry.       */
  1435. /*---------------------------------------------------------------------*/
  1436.     curr_ppc = pll_find(CURRENT_FILE->first_ppc,line_number);
  1437.     if (curr_ppc == NULL)  /* not found */
  1438.       {
  1439.        CURRENT_FILE->last_ppc = pll_add(CURRENT_FILE->first_ppc,CURRENT_FILE->last_ppc,sizeof(PPC));
  1440.        if (CURRENT_FILE->last_ppc == NULL)
  1441.          {
  1442.           display_error(30,"",FALSE);
  1443. #ifdef TRACE
  1444.           trace_return();
  1445. #endif
  1446.           return;
  1447.          }
  1448.        if (CURRENT_FILE->first_ppc == NULL)
  1449.           CURRENT_FILE->first_ppc = CURRENT_FILE->last_ppc;
  1450.        curr_ppc = CURRENT_FILE->last_ppc;
  1451.       }
  1452.     curr->pre = curr_ppc;
  1453.     strcpy(curr_ppc->ppc_command,temp_prefix_array);
  1454.     curr_ppc->ppc_line_number = line_number;
  1455.     curr_ppc->ppc_block_command = block_command;
  1456.     curr_ppc->ppc_cmd_idx = (-1);
  1457.    }
  1458. /*---------------------------------------------------------------------*/
  1459. /* Clear the pending prefix command line.                              */
  1460. /*---------------------------------------------------------------------*/
  1461.  memset(pre_rec,' ',PREFIX_WIDTH);
  1462.  pre_rec_len = 0;
  1463.  pre_rec[PREFIX_WIDTH] = '\0';
  1464.  if (redisplay_screen)
  1465.    {
  1466.     build_current_screen();
  1467.     display_current_screen();
  1468.    }
  1469. #ifdef TRACE
  1470.  trace_return();
  1471. #endif
  1472.  return;
  1473. }
  1474. /***********************************************************************/
  1475. #ifdef PROTO
  1476. short add_prefix_synonym(CHARTYPE *synonym,CHARTYPE *macroname)
  1477. #else
  1478. short add_prefix_synonym(synonym,macroname)
  1479. CHARTYPE *synonym,*macroname;
  1480. #endif
  1481. /***********************************************************************/
  1482. /* Parameters:                                                         */
  1483. /*    synonym: synonym for prefix macro                                */
  1484. /*  macroname: name of REXX macro file                                 */
  1485. /***********************************************************************/
  1486. {
  1487. /*--------------------------- local data ------------------------------*/
  1488.  LINE *curr=NULL;
  1489. /*--------------------------- processing ------------------------------*/
  1490. #ifdef TRACE
  1491.  trace_function("prefix.c:  add_prefix_synonym");
  1492. #endif
  1493. /*---------------------------------------------------------------------*/
  1494. /* First thing is to delete any definitions that may exist for the     */
  1495. /* supplied synonym.                                                   */
  1496. /*---------------------------------------------------------------------*/
  1497.  curr = first_prefix_synonym;
  1498.  while(curr != NULL)
  1499.    {
  1500.     if (strcmp(curr->name,synonym) == 0)
  1501.       {
  1502.        if (curr->name != NULL)
  1503.           (*the_free)(curr->name);
  1504.        if (curr->line != NULL)
  1505.           (*the_free)(curr->line);
  1506.        curr = lll_del(&first_prefix_synonym,&last_prefix_synonym,curr,DIRECTION_FORWARD);
  1507.       }
  1508.     else
  1509.        curr = curr->next;
  1510.    }
  1511. /*---------------------------------------------------------------------*/
  1512. /* Lastly append the synonym at the end of the linked list.            */
  1513. /*---------------------------------------------------------------------*/
  1514.  curr = lll_add(first_prefix_synonym,last_prefix_synonym,sizeof(LINE));
  1515.  if (curr == NULL)
  1516.    {
  1517.     display_error(30,(CHARTYPE *)"",FALSE);
  1518. #ifdef TRACE
  1519.     trace_return();
  1520. #endif
  1521.     return(RC_OUT_OF_MEMORY);
  1522.    }
  1523.  curr->line = (CHARTYPE *)(*the_malloc)((strlen(macroname)+1)*sizeof(CHARTYPE));
  1524.  if (curr->line == NULL)
  1525.    {
  1526.     display_error(30,(CHARTYPE *)"",FALSE);
  1527. #ifdef TRACE
  1528.     trace_return();
  1529. #endif
  1530.     return(RC_OUT_OF_MEMORY);
  1531.    }
  1532.  strcpy(curr->line,macroname);
  1533.  curr->name = (CHARTYPE *)(*the_malloc)((strlen(synonym)+1)*sizeof(CHARTYPE));
  1534.  if (curr->name == NULL)
  1535.    {
  1536.     display_error(30,(CHARTYPE *)"",FALSE);
  1537. #ifdef TRACE
  1538.     trace_return();
  1539. #endif
  1540.     return(RC_OUT_OF_MEMORY);
  1541.    }
  1542.  strcpy(curr->name,synonym);
  1543.  last_prefix_synonym = curr;
  1544.  if (first_prefix_synonym == NULL)
  1545.     first_prefix_synonym = last_prefix_synonym;
  1546. #ifdef TRACE
  1547.  trace_return();
  1548. #endif
  1549.  return(RC_OK);
  1550. }
  1551. /*man***************************************************************************
  1552. NAME
  1553.      find_prefix_synonym
  1554.  
  1555. SYNOPSIS
  1556.      CHARTYPE *find_prefix_synonym(synonym)
  1557.      CHARTYPE *synonym;
  1558.  
  1559. DESCRIPTION
  1560.      The find_prefix_synonym function finds a synonym for 'synonym'
  1561.      and returns that value. If no synonym exists, the 'synonym' is
  1562.      returned unchanged.
  1563.  
  1564.      This function is only available if REXX support is available.
  1565.      
  1566. RETURN VALUE
  1567.      Either the macroname associated with 'synonym' or 'synonym'.
  1568. *******************************************************************************/
  1569. #ifdef PROTO
  1570. CHARTYPE *find_prefix_synonym(CHARTYPE *synonym)
  1571. #else
  1572. CHARTYPE *find_prefix_synonym(synonym)
  1573. CHARTYPE *synonym;
  1574. #endif
  1575. /***********************************************************************/
  1576. {
  1577. /*-------------------------- external data ----------------------------*/
  1578. /*--------------------------- local data ------------------------------*/
  1579.  LINE *curr=NULL;
  1580. /*--------------------------- processing ------------------------------*/
  1581. #ifdef TRACE
  1582.  trace_function("prefix.c:  find_prefix_synonym");
  1583. #endif
  1584.  curr = first_prefix_synonym;
  1585.  while(curr != NULL)
  1586.    {
  1587.     if (strcmp(synonym,(CHARTYPE *)curr->name) == 0)
  1588.       {
  1589. #ifdef TRACE
  1590.        trace_return();
  1591. #endif
  1592.        return((CHARTYPE *)curr->line);
  1593.       }
  1594.     curr = curr->next;
  1595.    }
  1596. #ifdef TRACE
  1597.  trace_return();
  1598. #endif
  1599.  return(synonym);
  1600. }
  1601. /*man***************************************************************************
  1602. NAME
  1603.      find_prefix_oldname
  1604.  
  1605. SYNOPSIS
  1606.      CHARTYPE *find_prefix_oldname(oldname)
  1607.      CHARTYPE *oldname;
  1608.  
  1609. DESCRIPTION
  1610.      The find_prefix_oldname function finds the synonym for
  1611.      'oldname' and returns that value. If no synonym exists, the 
  1612.      'oldname' is returned unchanged.
  1613.  
  1614.      This function is only available if REXX support is available.
  1615.      
  1616. RETURN VALUE
  1617.      Either the synonym associated with 'oldname' or 'oldname'.
  1618. *******************************************************************************/
  1619. #ifdef PROTO
  1620. CHARTYPE *find_prefix_oldname(CHARTYPE *oldname)
  1621. #else
  1622. CHARTYPE *find_prefix_oldname(oldname)
  1623. CHARTYPE *oldname;
  1624. #endif
  1625. /***********************************************************************/
  1626. {
  1627. /*-------------------------- external data ----------------------------*/
  1628. /*--------------------------- local data ------------------------------*/
  1629.  LINE *curr=NULL;
  1630. /*--------------------------- processing ------------------------------*/
  1631. #ifdef TRACE
  1632.  trace_function("prefix.c:  find_prefix_oldname");
  1633. #endif
  1634.  curr = first_prefix_synonym;
  1635.  while(curr != NULL)
  1636.    {
  1637.     if (strcmp(oldname,(CHARTYPE *)curr->line) == 0)
  1638.       {
  1639. #ifdef TRACE
  1640.        trace_return();
  1641. #endif
  1642.        return(curr->name);
  1643.       }
  1644.     curr = curr->next;
  1645.    }
  1646. #ifdef TRACE
  1647.  trace_return();
  1648. #endif
  1649.  return(oldname);
  1650. }
  1651. /***********************************************************************/
  1652. #ifdef PROTO
  1653. CHARTYPE *get_prefix_command(LINETYPE prefix_index)
  1654. #else
  1655. CHARTYPE *get_prefix_command(prefix_index)
  1656. LINETYPE prefix_index;
  1657. #endif
  1658. /***********************************************************************/
  1659. {
  1660. /*--------------------------- local data ------------------------------*/
  1661. /*--------------------------- processing ------------------------------*/
  1662. #ifdef TRACE
  1663.  trace_function("prefix.c:  get_prefix_command");
  1664. #endif
  1665. /*---------------------------------------------------------------------*/
  1666. /* Just return a pointer to the prefix command associated with the     */
  1667. /* supplied index.                                                     */
  1668. /*---------------------------------------------------------------------*/
  1669. #ifdef TRACE
  1670.  trace_return();
  1671. #endif
  1672.  return(pc[prefix_index].cmd);
  1673. }
  1674.